Skip to content

fix(test): make issue-2898-comment.js assertion robust against flakiness#5208

Merged
mcollina merged 1 commit intomainfrom
fix/flaky-issue-2898-comment
May 5, 2026
Merged

fix(test): make issue-2898-comment.js assertion robust against flakiness#5208
mcollina merged 1 commit intomainfrom
fix/flaky-issue-2898-comment

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented May 5, 2026

Fixes #5189.

Problem

test/fetch/issue-2898-comment.js was flaky. The test used t.plan(2) with assertions placed inside the HTTP server's request handler callback. When the server callback didn't fire (e.g. if fetch failed before the request reached the server), the assertions were never run, causing a plan count mismatch and a generic 'test failed' failure.

Fix

Move the assertions out of the server request handler and into the test body. The server now resolves a Promise with the received headers, and the test asserts against them after the fetch() call completes. This ensures assertions always run in the test's execution context regardless of how the server behaves.

Move assertions from the HTTP server request handler callback into
the test body using a Promise to capture received headers. This avoids
the flakiness of t.plan() with assertions executed in an async server
callback, where the plan count could mismatch if fetch fails before
the request reaches the server.

Refs: #5189
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.27%. Comparing base (20711c6) to head (2139ecd).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5208   +/-   ##
=======================================
  Coverage   93.27%   93.27%           
=======================================
  Files         110      110           
  Lines       36349    36349           
=======================================
  Hits        33904    33904           
  Misses       2445     2445           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina merged commit 2fb132c into main May 5, 2026
57 of 61 checks passed
@mcollina mcollina deleted the fix/flaky-issue-2898-comment branch May 5, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flaky] test\fetch\issue-2898-comment.js

3 participants